#ifndef __TUNER_RESTREAM_STUFF
#define __TUNER_RESTREAM_STUFF

/*
 *   This file is part of ed_pvr.
 *
 *   ed_pvr is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   ed_pvr is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with ed_pvr.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifdef __cplusplus
    extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
#include "device.h"
#include "timers.h"
#include "xmltv.h"
#include "win.h"
#include "mpegts_io.h"

#define RESTREAM_MAX_CHAN_GROUPS	24

#define RESTREAM_REC_IDX_FILE		0
#define RESTREAM_REC_TS_FILE		1
#define RESTREAM_REC_START_TIME		2
#define RESTREAM_REC_END_TIME		3
#define RESTREAM_REC_CHANNEL_NUM	4
#define RESTREAM_REC_CHANNEL_NAME	5
#define RESTREAM_REC_URL			6
#define RESTREAM_REC_TITLE			7
#define RESTREAM_REC_PLOT			8
#define RESTREAM_REC_PLOT_OUTLINE	9
#define RESTREAM_REC_GENRE			10
#define RESTREAM_REC_SUBGENRE		11

#define RESTREAM_EPG_PROTO_STR		"etp:"


#define RESTREAM_REMOTE_TYPE_LOCAL	0
#define RESTREAM_REMOTE_TYPE_HLS	1
#define RESTREAM_REMOTE_TYPE_NONE	0xFF

struct restream_url
{
	uint8_t used;
	char *tuner_url;
};
typedef struct restream_url RESTREAM_URL;


struct restream_channel_group
{
	uint8_t type;
	char base_url[4096];
	uint8_t tuner_count;
};
typedef struct restream_channel_group RESTREAM_CHANNEL_GROUP;


struct restream_channel_url_list
{
	uint8_t count;
	RESTREAM_URL list[255];
};
typedef struct restream_channel_url_list RESTREAM_CHANNEL_URL_LIST;


struct tuner_restream_struct
{
	DEVICE_STRUCT *device;
	char *xmltv_file;
	char *timer_file;
	char *recording_dir;
	char *channels_file;
	pthread_mutex_t init_mutex;
	pthread_mutex_t recording_mutex;
	TIMER_CONTROL_STRUCT * timer_ctl;
	uint8_t tun_chan_group_count;
	RESTREAM_CHANNEL_GROUP tun_chan_group[RESTREAM_MAX_CHAN_GROUPS];
	RESTREAM_CHANNEL_URL_LIST *url_list;
	MPEGTS_IO_RECORDINGS_STRUCT * recordings;
	NCURSES_SCREEN *screen;
	XMLTV_STRUCT *xmltv_cache;
	pthread_mutex_t xmltv_mutex;
	uint8_t xmltv_display_index;
	uint8_t	init_done;
	uint8_t recording_cleanup;
};
typedef struct tuner_restream_struct TUNER_RESTREAM_STRUCT;

TUNER_RESTREAM_STRUCT * tuner_restream_init(DEVICE_INIT_ARGS_STRUCT *);
#ifdef __cplusplus
    }
#endif


#endif
